﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace CSP.Core
{
    //public enum SharepointGroupsEnum
    //{
    //    Citizens,
    //    CivilServants
    //};

    public static class MembershipHelper
    {
        public static bool IsCurrentUserCitizen()
        {
            try
            {
                bool ret = false;
                if (SPContext.Current.Web.CurrentUser != null)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        ResourceFile resFile = new ResourceFile();
                        string resourceValue = resFile.LoadResource("CSP_citizensgroup_title");
                        ret = SPContext.Current.Web.SiteGroups[resourceValue].ContainsCurrentUser;
                    });
                }
                return ret;
            }
            catch
            {
                return false;
            }
        }

        public static bool IsCurrentUserCivilServant()
        {
            try
            {
                bool ret = false;
                if (SPContext.Current.Web.CurrentUser != null)
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        ResourceFile resFile = new ResourceFile();
                        ret = SPContext.Current.Web.SiteGroups[resFile.LoadResource("CSP_civilservantsgroup_title")].ContainsCurrentUser;
                    });
                }
                return ret;
            }
            catch
            {
                return false;
            }
        }

    }
}
